<?php

class Offer_model extends CI_Model {

	function __construct() {
		parent::__construct();
	}

	function get_offer($offer_id) {
		$sql = "SELECT * FROM offer WHERE offer_id = ? " ;
		$query = $this->db->query($sql, $offer_id);
		if($query->num_rows() > 0){
			$data = $query->row_array();	
		}
		return $data;
	}
	
	function get_category() {
		$query = $this->db->query("SELECT * FROM category");
		if ($query->num_rows() > 0){
			foreach ($query->result_array() as $row) {
				$data[] = $row;
			}
		}
		return $data ;
	}
	
	function get_sub_category() {
		$query = $this->db->query("SELECT * FROM sub_category");
		if ($query->num_rows() > 0){
			foreach ($query->result_array() as $row) {
				$data[] = $row;
			}
		}
		return $data ;
	}
	 
	function submit_offer($item_title, $item_price, $item_pic, $item_condition, $item_desc, $age_year, 
							$age_month, $category_id, $sub_category_id, $fb_id) {
		$sql = "INSERT INTO offer (item_title, item_price, item_pic, item_condition, item_desc, age_year, 
								age_month, category_id, sub_category_id, fb_id, date_created) 
			  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())";
		$this->db->query($sql, array(strip_tags($item_title), $item_price, $item_pic, 
									$item_condition, strip_tags($item_desc), 
									$age_year, $age_month, $category_id, $sub_category_id, $fb_id));
		return mysql_insert_id();
	}
	
	function update_offer($offer_id, $item_title, $item_price, $item_pic, $item_condition, $item_desc, 
							$age_year, $age_month, $category_id, $sub_category_id) {
		$sql = "UPDATE offer SET item_title = ?, item_price = ?, item_pic = ?, item_condition = ?, item_desc = ?, 
				age_year = ?, age_month = ?,category_id = ?, sub_category_id = ? WHERE offer_id = ?" ;
		$this->db->query($sql, array(strip_tags($item_title), $item_price, $item_pic, 
									$item_condition, strip_tags($item_desc), 
									$age_year, $age_month, $category_id, $sub_category_id, $offer_id));
	}
}

?>